indusfandomcom-20200214-history
Agent Implementation types
Agents are mapped to roles. A role may be played by a class of actors, for example, a software programmer. The name of an Agent will usually refer to its role in Indus. Roles, in turn, are of two types : * Roles that can be played by several actors of a class simultaneously, that is, several instances of such roles may co-exist at one time. * Roles that can be played by several actors of a class one at a time, that is, only instance of such roles may exist at one time across a network. Above, the first represents User Agents whereas the latter represents Process Agents. Both User agents and Process agents are history aware and transactional. User agents have a primary key which is a combination of the role played by the agent and the ID of its instance. In contrast, Process agents have a primary key that only indicates its role. This is because a Process agent cannot have multiple instances co-existing across a network at any one point in time. We set the agent type as: setServantType("USER"); //if the implementation type is USER setServantType("PROCESS"); //if implementation type is PROCESS In the following case where, Teacher Physics = newType Teacher(Rob); //Teacher is a role that Rob plays Teacher Chemistry = newType Teacher(Chris); // Chemistry is the client handle to Chris Teacher Physics = newType Teacher(Mary); // Mary takes over the Physics handle from Rob Teacher Physics = newType Teacher(Rob); // Physics now points to the first Rob instance TeacherName = Physics.whoisteaching( ); In the above case, Teacher is a User agent as IDs (Rob, Chris, Mary) are used to identify the agent instances. Each agent instance has a client side handle (Physics, Chemistry) which point to server/container side instances whose lifecycle is managed by the Indus container. In the following case where, Principal Rob = newType Principal( ); // Rob is the Principal now Principal Bill = newType Principal( ); // Bill cannot take over Rob as Principal till Rob exits PrincipalName = Principal.WhoAmI( ); In the above case, Principal is a Process agent as all client handles (Rob, Bill) are used to identify the server side instance Principal one after the other. Here, the Indus container will allow Bill to point to Principal only and only if Rob is not pointing to Principal anymore. Example 2: User agent public class StaffCommander implements Commander{ Context{ setServantType("PROCESS"); //there can be only one commander at any one point in time } public static void main(String[] args){ StaffCommander Cmdr = newType StaffCommander(null); OfficerOnDuty MorningShift = newType OfficerOnDuty("Rob"); MorningShift.AddRank("Captain"); //Rob is a Captain String MOff = MorningShift.WhoIsOnDuty(); System.out.println(MOff + " Rob is working on the Morning Shift"); OfficerOnDuty NoonShift = newType OfficerOnDuty("Chris"); NoonShift.AddRank("Major"); //Chris is a Major String NOff = NoonShift.WhoIsOnDuty(); System.out.println(NOff + " Chris is working on the Noon Shift"); OfficerOnDuty MorningShift = newType OfficerOnDuty("Chris"); MorningShift.AddRank("Major"); //Chris has taken over from Rob on the morning shift String M2Off = MorningShift.WhoIsOnDuty(); System.out.println("Chris, a " + M2Off + " is working on the Morning Shift"); OfficerOnDuty MorningShift = newType OfficerOnDuty("Rob"); String M3Off = MorningShift.WhoIsOnDuty(); //Rob returns to the duty on the morning shift System.out.println(M3Off + "Rob has returned back to the Morning Shift"); } } In the above example, Rob and Chris are instances of the User agent called Officer on Duty that exchanges roles on working on the Morning shift. Here, MorningShift is a client side handle that Rob and Chris (both server/container side instances of the OfficerOnDuty agent) exchange from time to time. Example 3. Process agent public static void main(String[] args){ try{ SchoolPrincipal ModernSchool = newType SchoolPrincipal(null); }catch (Exception e){ } try{ SchoolStudent StdXII = newType SchoolStudent("Ajay"); String PName = StdXII.WhoIsYourPrincipal( ); System.out.println("I am Ajay." + PName + " is the Principal of Modern School."); try{ SchoolStudent StdX = newType SchoolStudent("Navin"); StdX.TryChangeYourPrincipal( ); String CPName = StdX.WhoIsYourPrincipal( ); System.out.println("I am Navin. I tried changing the School's Principal. " + CPName + " is the Modern School Principal now."); }catch(Exception e){ } String PrName = StdXII.WhoIsYourPrincipal( ); System.out.println("I am Ajay again. " + PrName + " is the Modern School Principal now."); }catch (Exception e){ } } In the example above, two school students that are instances of an user agent called SchoolStudent try to replace a school principal that is an instance of a process agent called SchoolPrincipal. This example shows that there could be at the most a single instance created of a Process agent. Next : Component implementation types